import { runAsWorker } from "synckit";

export type ResolvePrettierOptionsFn = (onDiskFilepath: string) => import("prettier").Options;

// const vuePrettierOptions: import("prettier").Options = {
//   tabWidth: 2,
//   useTabs: false,

//   bracketSameLine: true,
//   jsxBracketSameLine: true,
//   singleAttributePerLine: true,
//   vueIndentScriptAndStyle: true,
//   htmlWhitespaceSensitivity: "ignore",

//   arrowParens: "avoid",
//   trailingComma: "es5",
//   singleQuote: false,
//   printWidth: 150,
// };

let prettier: typeof import("prettier");

runAsWorker(async (onDiskFilepath: string) => {
  if (!prettier) {
    prettier = await import("prettier");
  }
  // 获取 .prettierrc.js 配置
  const prettierRcOptions = await (function () {
    return prettier.resolveConfig(onDiskFilepath, {
      editorconfig: true,
    });
  })();

  // const prettierOptions = { ...vuePrettierOptions, ...prettierRcOptions };

  // Skip if file is ignored using a .prettierignore file
  return prettierRcOptions;
});
